package edu.pku.sei.transformation.editor.views.figures;

import java.util.List;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;

import edu.pku.notation.runtime.constance.ColorConstance;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class TransformationFigure extends Figure {
	private Label tag = new Label();
	private Label head = new Label();
	private Figure body = new Figure();
	private static final int HEAD_MARGIN = 1;
	private static final int BODY_MARGIN = 1;
	public TransformationFigure() {
		this.setLayoutManager(new ToolbarLayout());
		LineBorder border = new LineBorder();
		this.setBorder(border);
		
		tag.setFont(FontConstant.STEREO_TYPE_LABEL);
		this.add(tag);
		head.setFont(FontConstant.TITLE_FONT);
		head.setIcon(IconsProvider.getImage(IconsProvider.TRANSFORMATION_ICO));
		head.setBorder(new MarginBorder(HEAD_MARGIN));
		this.add(head);
		
		body.setBorder(new ContainerBorder(ColorConstance.BLACK, 1, BODY_MARGIN, BODY_MARGIN,
				BODY_MARGIN, BODY_MARGIN));
		ToolbarLayout bodyLayout = new ToolbarLayout();
		bodyLayout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
		bodyLayout.setStretchMinorAxis(false);
		body.setLayoutManager(bodyLayout);
		this.add(body);
		
	}
	
	public void setName(String name) {
		head.setText(name);
	}
	
	public void setBody (List<Label> labels) {
		body.removeAll();
		for (Label label : labels) {
			label.setFont(FontConstant.BODY_FONT);
			body.add(label);
		}
	}
	
	public void setTag(String tag) {
		this.tag.setText(tag);
	}
}
